<?
 include("../header.php");
 include("../lib/config.php");
 	$nik 		= $HTTP_GET_VARS['nik'];
 	$periode 	= $HTTP_GET_VARS['periode'];
	//$show 	= $HTTP_GET_VARS['show'];
	$nikg		= $HTTP_GET_VARS['nikg'];
	$nama		= $HTTP_GET_VARS['nama'];
	$no			= $HTTP_GET_VARS['no'];
	$no_res		= $HTTP_GET_VARS['no_res'];
	$op			= $HTTP_GET_VARS['op'];
	$st			= $HTTP_GET_VARS['st']; // approval
	//$pengajuan	= $HTTP_POST_VARS['pengajuan']; // pengajuan default: yes
	$pengajuan	= $HTTP_GET_VARS['pengajuan']; // pengajuan default: yes
	if($op == "edit"){
		$Faction = "../lib/update.php";
		$VButton = "Update";
		$sql = mssql_query("SELECT CONVERT(CHAR(12), tanggal, 103) TglRes, * FROM MedicalRestitusiDetail WHERE NIK='".$nikg."' AND nomor='$no_res'",$conn);
		$row = mssql_fetch_array($sql);
		$periode = $row[Periode];
		$status = "medical_edit";
	}
	elseif($st == "setuju"){
		$Faction = "../lib/update.php";
		$Vbutton = "Setujui";
		$sql = mssql_query("SELECT CONVERT(CHAR(12), tanggal, 103) TglRes, CONVERT(CHAR(12), tgl_bayar, 103) TglBayar, * FROM MedicalRestitusiDetail WHERE NIK='".$nikg."' AND nomor='$no_res'",$conn);
		$row = mssql_fetch_array($sql);
		$periode = $row[Periode];
		$status = "medical_setuju";
		$VButton = "Disetujui";
	}
	else{
		$Faction 	= "../lib/save.php";
		$VButton 	= "Simpan";
		$sql 		= mssql_query("SELECT * FROM Karyawan WHERE NIK='$nik' ",$conn);
		$row 		= mssql_fetch_array($sql);
	}
 ?>

<script language="javascript" src="../js/urchin.js"></script>
<script language="javascript" src="../js/event.js"></script>
 <script type="text/javascript">
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};
	///////////////////// VALIDASI FORM ////////////////////////////
	function Validate(){
		var F = document.forms[0];
		
		if(F.nik.value == ""){
			alert("Maaf, NIK tidak boleh kosong ... ");
			F.nik.focus();
			return false;
		}
		
		if(F.no_restitusi.value == ""){
			alert("Maaf, Nomor Restitusi tidak boleh kosong ... ");
			F.no_restitusi.focus();
			return false;
		}
		
		if(F.tgl_restitusi.value == ""){
			alert("Maaf, Tanggal Restitusi tidak boleh kosong ... ");
			F.tgl_restitusi.focus();
			return false;
		}
<?
	if($st == "setuju"){
?>
		if(F.tgl_bayar.value == ""){
			alert("Maaf, Tanggal Bayar tidak boleh kosong ... ");
			F.tgl_bayar.focus();
			return false;
		}
<?
	}
?>
		if(F.nama_tertanggung1.value == ""){
			alert("Maaf, Nama Tertanggung tidak boleh kosong ... ");
			F.nama_tertanggung1.focus();
			return false;
		}

		if(F.status_keluarga1.value == ""){
			alert("Maaf, Status Keluarga Restitusi tidak boleh kosong ... ");
			F.status_keluarga1.focus();
			return false;
		}

		if(F.nama_dokter1.value == ""){
			alert("Maaf, Nama Dokter/Rumah Sakit/Apotik/Optik tidak boleh kosong ... ");
			F.nama_dokter1.focus();
			return false;
		}
		
		<?
		if($pengajuan == "yes" || $op == "edit"){
		
		}
		else{
		?>
		
		if(F.mata_anggaran1.value == ""){
			alert("Maaf, Mata Anggaran tidak boleh kosong ... ");
			F.mata_anggaran1.focus();
			return false;
		}
		
		<?
		}
		?>
		
		if(F.diajukan1.value == ""){
			alert("Maaf, Nominal yang diajukan tidak boleh kosong ... ");
			F.diajukan1.focus();
			return false;
		}
		F.submit();		
	}
	
	function show_popup3(page)
	{
		var test=document.FEmployee.nik.value;
		var nama=document.FEmployee.nama.value;

		child = open
		(
			"list_family.php?nik="+ test +"&no="+page+"&nama="+nama+"",
			"",
			"scrollbars,width=300,height=400,left=150,top=150"
		);
	}

	function show_popup2(page)
	{
		//var test=document.FEmployee.nik.value;
		//var nama=document.FEmployee.nama.value;

		child = open
		(
			"list_mata_anggaran.php?no="+page+"",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}
	
	function show_emp(page)
	{
		child = open
		(
			"frm_list_emp.php",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}

 </script>
 <form name="FEmployee" method="post" action="<?=$Faction?>">
 <table width="100%" class="table_indent2" cellpadding="0" cellspacing="0">
  <?
  	// untuk no_restitusi
	$depan 		= date("Ymdhis");
	$belakang	= mt_rand(1,100);
	$nores		= $depan.$belakang;
	
	// tanggal
	$tanggal	= date("d")."/".date("m")."/".date("Y"); 
  ?>
  <tr>
   <td align="right"><b>No. Restitusi: <input name="no_restitusi" type="text" style="border:none;" readonly="readonly" value="<?
   if($op == "edit" || $st == "setuju"){
   		echo"$row[nomor]";
   }
   else{
   		echo"$nores";
   }
   
   ?>" /> &nbsp;&nbsp;</td>
  </tr>
  <tr>
   <td align="right"><b>Tanggal: <input name="tgl_restitusi" type="text" style="border:none;" value="<?
   if($op == "edit" || $st == "setuju"){
   		echo"$row[TglRes]";
   }
   else{
   		echo"$tanggal";
   }
   ?>" <?
   if($op == "edit" || $st == "setuju"){
   		echo" readonly";
   }
   else{
   		//echo"$tanggal";
   }
   ?>
    /></td>
  </tr>
  <tr>
   <td align="right"><b>Tanggal Bayar:</b> <input type="text" size="10" readonly="readonly" value="<?=$row[TglBayar]?>" name="tgl_bayar" style="border:none;" /> <span class="required">*</span> 
  <a href="javascript:calB.popup();"><img src="<?=$path?>/images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> </td>
  </tr>
 </table>
 <table width="100%">
 <tr>
  <td>
  <table>
   <tr> 
    <td width="150">NIK</td>
	<td><input type="text" name="nik"  value="<?=$row[NIK]?>" readonly="" /> 	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_emp()'><img src='../images/people.png' border=0></a>";
		}
	?>
</td>
   </tr>
   <tr> 
    <td>Nama</td>
	<td><input type="text" name="nama" size="50" value="<?
    if(empty($row[Nama])){
		$sql2 		= mssql_query("SELECT * FROM Karyawan WHERE NIK='$nikg' ",$conn);
		$row2		= mssql_fetch_array($sql2);
		echo"$row2[Nama]";
	}
	else{
		echo"$row[Nama]";
	}
	?>" readonly=""  /></td>
   </tr>
   <?
   	// get karir paling terakhir
	$sqlgkl = mssql_query("SELECT kode_so1, kode_so2 FROM VKarirPTSI WHERE NIK='$nik' ORDER BY seqno DESC",$conn);
	$rowgkl = mssql_fetch_array($sqlgkl);
	// kode so
	if(empty($rowgkl[kode_so1])){
		$kodeso = $rowgkl[kode_so2];
	}
	else{
		$kodeso = $rowgkl[kode_so1];
	}
	
	// 000000000000
	// 123456789012
	// 012345678901
	// 1111111
	if(trim($kodeso)== ""){
	}
	else{
		$s1 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'", $conn);
		if(mssql_num_rows($s1) > 0){
			$r1 = mssql_fetch_array($s1);
			$divisi = $r1[uraian];
		}
	}	

	//$sql = mssql_query("SELECT * FROM VLevelCabang WHERE kode_so='$divisi'",$conn);
	//$row = mssql_fetch_array($sql);
   ?>
   <tr>
    <td>Divisi/Biro/Unit Kerja:</td>
	<td><?=$divisi?></td>
   </tr>
  </table>
  </td>
 </tr>
 <tr>
  <td><hr noshade="noshade" size="-1" color="#CCCCCC" /></td>
 </tr>
 <tr>
  <td>Periode: <input style="text-align:right;" type="text" maxlength="4" size="5" name="periode" readonly="" value="<?
   if($op == "edit" || $st == "setuju"){
   		echo"$row[Periode]";
   }
   else{
   		if(empty($periode)){
			echo date("Y");
		}
		else{
	   		echo"$periode";
		}
   }
  ?>" />  <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>
   <fieldset>
   <legend>Pengajuan Restitusi</legend>
   <table width="100%">
    <tr class="headlist">
     <td rowspan="2">No.</td>
     <td rowspan="2">Nama Tertanggung</td>
     <td rowspan="2">Status Keluarga</td>
     <td rowspan="2">Nama Dokter/RS/Apotik</td>
     <td rowspan="2">Kode Mata Anggaran</td>
     <td colspan="2">Jumlah</td>
    </tr>
    <tr class="headlist">
     <td>Diajukan</td>
     <td>Disetujui</td>
    </tr>
    <?
		if($op == "edit" || $st == "setuju"){
			$sql3 = mssql_query("SELECT ROW_NUMBER() OVER(ORDER BY id_trans) AS No, * FROM MedicalRestitusiDetail WHERE NIK='$nikg' AND nomor='$no_res'");
			while($row3 = mssql_fetch_array($sql3)){
				?>
                
                <tr class="contentlist">
                 <td align="right" valign="middle"><?=$row3[No]?></td>
                 <td><input type="text" name="nama_tertanggung<?=$row3[No]?>" value="<?=$row3[nama_tertanggung]?>" /> <a href="Javascript:show_popup3('<?=$row3[No]?>')"><img src="../images/folder_txt.png" border="0" /></a></td>
                 <td><input type="text" size="10" name="status_keluarga<?=$row3[No]?>" value="<?=$row3[status_kel]?>" /></td>
                 <td><input type="text" name="nama_dokter<?=$row3[No]?>" value="<?=$row3[nama_dokter]?>" /></td>
                 <td>
                 <input type="hidden" name="kode_mata_anggaran<?=$row3[No]?>" value="<?=$row3[mata_anggaran]?>" />
                 <?
				 //if($st == "setuju"){
				 	//if(empty($row3[mata_anggaran])){
					 //	$diisi = "";
					//}
					//else{
					 	$diisi = $row3[mata_anggaran];
					//}
				 //}
                 //elseif($pengajuan == "yes" || $op == "edit" || empty($op)){
				 	//if(empty($row3[mata_anggaran])){
					 //	$diisi = "Diisi oleh Admin";
					//}
					//else{
					 //	$diisi = $row3[mata_anggaran];
					//}
                 //}
				 ?>
                 <input type="text" name="mata_anggaran<?=$row3[No]?>" size="10" value="<?=$diisi?>" />
                 <?
                 	//if($st == "setuju"){
				 ?>
                 <a href="Javascript:show_popup2('<?=$row3[No]?>')">
                 <?
				 //}
				 //else{
				 ?>
                 <?
				 //}
                 ?><img src="../images/folder_txt.png" border="0" /></a></td>
                 <td><input type="text" value="<?=$row3[jml_diajukan]?>" name="diajukan<?=$row3[No]?>"/><input type="hidden" name="ID<?=$row3[No]?>" value="<?=$row3[id_trans]?>"/></td>
                 <td><input type="text" value="<?
                 if($st == "setuju"){
					 echo $row3[jml_diajukan];
				 }
				 else{
					 echo $row3[jml_disetujui];				 
				 }
				 
				 ?>" name="disetujui<?=$row3[No]?>"
                 <?
                 if($pengajuan == "yes"  || $op == "edit"){
                    echo" readonly";
                 }
                 ?>
                  /></td>
                </tr>
                <tr class="contentlist">
                 <td colspan="5">&nbsp;</td>
                 <td colspan="2">
                 <b>Keterangan:</b><br />
                 <textarea name="remarks<?=$row3[No]?>" rows="1" style="width:280px;" wrap="soft"><?=$row3[Remarks]?></textarea>
                 </td>
                </tr>
                <?
			}
		}
		// jika bikin baru
		else{
    	for($i=1;$i<=10;$i++){
	?>
    <tr class="contentlist">
     <td align="right"><?=$i?></td>
     <td><input type="text" name="nama_tertanggung<?=$i?>" /> <a href="Javascript:show_popup3('<?=$i?>')"><img src="../images/folder_txt.png" border="0" /></a></td>
     <td><input type="text" size="10" name="status_keluarga<?=$i?>" /></td>
     <td><input type="text" name="nama_dokter<?=$i?>" /></td>
     <td>
     <input type="hidden" name="kode_mata_anggaran<?=$i?>" value="" />
     <input type="text" name="mata_anggaran<?=$i?>" size="10" readonly="readonly" value="<?
     //if($pengajuan == "yes"){
	 	//echo"Diisi oleh Admin";
	 //}
	 ?>" /> <?
     //if($st == "yes"){
     ?>
	 <a href="Javascript:show_popup2('<?=$i?>')">
     <?
     //}
	 ?>
     <img src="../images/folder_txt.png" border="0" /></a></td>
     <td><input type="text" name="diajukan<?=$i?>"/></td>
     <td><input type="text" name="disetujui<?=$i?>"
     <?
     if($pengajuan == "yes" || $op == "edit"){
	 	echo" readonly";
	 }
	 ?>
      /></td>
    </tr>
    <?
    	}
		}
	?>
   </table>  
   </fieldset>
  </td>
 </tr>
 <tR>
  <td align="center">
  <input type="hidden" name="cat" value="medical" />
  <input type="hidden" name="status" value="<?=$status?>" />
   <input type="button" value="Batal" onclick="Javascript:history.back();" class="button" />
  <input type="reset" value="Reset" class="button" /> <input type="button" onclick="Javascript:Validate();" value="<?=$VButton?>" class="button" />
  </td>
 </tR>
</table>
</form>
</body>
</html>
<script type="text/javascript">
var f = document.forms[0];
<?
	if($op == "edit" || $st == "setuju"){
		// get jumlah pengajuan
		$jmlxxx = mssql_num_rows($sql3);
		for($k=1;$k<=$jmlxxx;$k++){
		?>
		MaskInput(f.diajukan<?=$k?>,"9999999999999999");
		MaskInput(f.disetujui<?=$k?>,"9999999999999999");
		<?
	}
	}
//	}
	else{
?>

//var f = document.forms[0];
<?
	for($k=1;$k<=10;$k++){
?>
MaskInput(f.diajukan<?=$k?>,"9999999999999999");
MaskInput(f.disetujui<?=$k?>,"9999999999999999");
<?
	}
	}
?>
/*
MaskInput(f.tgl_bayar,"99/99/9999");
MaskInput(f.tgl_kwitansi,"99/99/9999");
MaskInput(f.beban_RI_prsh,"9999999999999999");
MaskInput(f.beban_RI_kar,"9999999999999999");
MaskInput(f.beban_PR_prsh,"9999999999999999");
MaskInput(f.beban_PR_kar,"9999999999999999");  
MaskInput(f.klaim_RJ,"9999999999999999");
MaskInput(f.klaim_RI,"9999999999999999");
MaskInput(f.klaim_KM,"9999999999999999");
MaskInput(f.setuju_RJ,"9999999999999999");
MaskInput(f.setuju_RI,"9999999999999999");
MaskInput(f.setuju_KM,"9999999999999999");
*/
<?
	//}
?>
</script>
<script type="text/javascript">
// script untuk popup calendar
<?
	if($st == "setuju"){
?>
	var calB = new calendar1(document.forms[0].elements['tgl_bayar']);
	calB.year_scroll = true;
	calB.time_comp = false;	
<?
	}
?>
</script>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>